<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0 ;
            padding: 0;

        }
        .one{
            width: 300px;
            height: 300px;
            background-color: red;
            margin-left:300px;
            margin-top:100px;
            position: relative;
        }
        .two{
            width: 50px;
            height: 50px;
            background-color: blue;
        }
    </style>
</head>
<body>
    

    <div class="one">
        <div class="two"></div>

    </div>
    <script>
        let one = document.querySelector(".one");
        let two = document.querySelector(".two");
        console.log(one.offsetLeft);
        console.log(one.offsetTop);
        console.log(two.offsetLeft);
        console.log(two.offsetTop);
        //获取元素相对于页面的坐标
        //如果父级有定位则 会 更改参考目标 变为父级  也就是变为 元素相对于父级的坐标
        
    </script>
</body>
</html>